public class L844 {


    public static void main(String[] args) {
        String s = "a##c";
        String t = "#a#c";

        boolean b = new Solution().backspaceCompare(s, t);

        System.out.println(b);
    }
}


class Solution {
    public boolean backspaceCompare(String s, String t) {

        int i = s.length() - 1;
        int j = t.length() - 1;

        int i1 = 0;
        int j1 = 0;

        while (i >= 0 || j >= 0) {
            if (i >= 0 && s.charAt(i) == '#') {
                i1++;
                i--;
                continue;
            }
            if (j >= 0 && t.charAt(j) == '#') {
                j1++;
                j--;
                continue;
            }
            if (i1 > 0) {
                i--;
                i1--;
                continue;
            }
            if (j1 > 0) {
                j--;
                j1--;
                continue;
            }
            if (i >= 0 && j >= 0) {
                if (s.charAt(i) != t.charAt(j)) {
                    return false;
                } else {
                    i--;
                    j--;
                }
            } else {
                return false;
            }
        }
        return true;
    }
}
